<?php

/**
 * 积分类型管理
 * @author  Mr.L <349865361@qq.com>
 */

namespace app\member\admin;

class PointsClassAdmin extends \app\system\admin\SystemExtendAdmin {

    protected $_model = 'PointsClass';

    /**
     * 模块信息
     */
    protected function _infoModule() {
        return [
            'info' => [
                'name' => '积分类型',
                'description' => '管理积分类型',
            ],
            'fun' => [
                'index' => true,
                'add' => true,
                'edit' => true,
                'del' => true
            ]
        ];
    }


    protected function _editBefore() {
        if($_POST['class_id'] == 1 && $_POST['label'] <> 'point') {
            $this->error('默认标识不能更改！');
        }
    }


    protected function _delBefore($id) {
        if($id == 1) {
            $this->error('保留类型无法删除！');
        }
        $info = target($this->_model)->getInfo($id);
        $count = target('member/PointsAccount')->countList([
            'A.label' => $info['label']
        ]);
        if ($count > 0) {
            $this->error('请先删除该分类下的积分账户！');
        }
    }


}